package cn.kduck.code.module.web;

import cn.kduck.code.module.service.Module;
import cn.kduck.code.module.service.ModuleService;
import cn.kduck.core.web.json.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/code/generate/module")
public class ModuleController {

    @Autowired
    private ModuleService moduleService;

    @PostMapping("/add")
    public JsonObject addModule(Module module,@RequestParam("entityIds") String[] entityIds){
        moduleService.addModule(module,entityIds);
        return JsonObject.SUCCESS;
    }

    @PutMapping("/update")
    public JsonObject updateModule(Module module,@RequestParam("entityIds") String[] entityIds){
        moduleService.updateModule(module,entityIds);
        return JsonObject.SUCCESS;
    }

    @DeleteMapping("/delete")
    public JsonObject deleteModule(@RequestParam("ids") String[] ids){
        moduleService.deleteModule(ids);
        return JsonObject.SUCCESS;
    }

    @GetMapping("/get")
    public JsonObject getModule(@RequestParam("moduleId") String moduleId){
        Module module = moduleService.getModule(moduleId);
        return new JsonObject(module);
    }

    @GetMapping("/list")
    public JsonObject getModule(){
        List<Module> moduleList = moduleService.listModule();
        return new JsonObject(moduleList);
    }


}
